// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

/// <summary>
/// <para><see href="https://www.elastic.co/guide/en/elasticsearch/reference/8.15/query-dsl.html">Learn more about this API in the Elasticsearch documentation.</see></para>
/// </summary>
[JsonConverter(typeof(QueryConverter))]
public sealed partial class Query
{
	internal Query(string variantName, object variant)
	{
		if (variantName is null)
			throw new ArgumentNullException(nameof(variantName));
		if (variant is null)
			throw new ArgumentNullException(nameof(variant));
		if (string.IsNullOrWhiteSpace(variantName))
			throw new ArgumentException("Variant name must not be empty or whitespace.");
		VariantName = variantName;
		Variant = variant;
	}

	internal object Variant { get; }
	internal string VariantName { get; }

	public static Query Bool(Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery boolQuery) => new Query("bool", boolQuery);
	public static Query Boosting(Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery boostingQuery) => new Query("boosting", boostingQuery);
	public static Query CombinedFields(Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery combinedFieldsQuery) => new Query("combined_fields", combinedFieldsQuery);
	public static Query ConstantScore(Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery constantScoreQuery) => new Query("constant_score", constantScoreQuery);
	public static Query DisMax(Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery disMaxQuery) => new Query("dis_max", disMaxQuery);
	public static Query DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.UntypedDistanceFeatureQuery distanceFeatureQuery) => new Query("distance_feature", distanceFeatureQuery);
	public static Query DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceFeatureQuery distanceFeatureQuery) => new Query("distance_feature", distanceFeatureQuery);
	public static Query DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.DateDistanceFeatureQuery distanceFeatureQuery) => new Query("distance_feature", distanceFeatureQuery);
	public static Query Exists(Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery existsQuery) => new Query("exists", existsQuery);
	public static Query FunctionScore(Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery functionScoreQuery) => new Query("function_score", functionScoreQuery);
	public static Query Fuzzy(Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery fuzzyQuery) => new Query("fuzzy", fuzzyQuery);
	public static Query GeoBoundingBox(Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery geoBoundingBoxQuery) => new Query("geo_bounding_box", geoBoundingBoxQuery);
	public static Query GeoDistance(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery geoDistanceQuery) => new Query("geo_distance", geoDistanceQuery);
	public static Query GeoShape(Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery geoShapeQuery) => new Query("geo_shape", geoShapeQuery);
	public static Query HasChild(Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery hasChildQuery) => new Query("has_child", hasChildQuery);
	public static Query HasParent(Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery hasParentQuery) => new Query("has_parent", hasParentQuery);
	public static Query Ids(Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery idsQuery) => new Query("ids", idsQuery);
	public static Query Intervals(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery intervalsQuery) => new Query("intervals", intervalsQuery);
	public static Query Knn(Elastic.Clients.Elasticsearch.KnnQuery knnQuery) => new Query("knn", knnQuery);
	public static Query Match(Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery matchQuery) => new Query("match", matchQuery);
	public static Query MatchAll(Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery matchAllQuery) => new Query("match_all", matchAllQuery);
	public static Query MatchBoolPrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery matchBoolPrefixQuery) => new Query("match_bool_prefix", matchBoolPrefixQuery);
	public static Query MatchNone(Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery matchNoneQuery) => new Query("match_none", matchNoneQuery);
	public static Query MatchPhrase(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery matchPhraseQuery) => new Query("match_phrase", matchPhraseQuery);
	public static Query MatchPhrasePrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery matchPhrasePrefixQuery) => new Query("match_phrase_prefix", matchPhrasePrefixQuery);
	public static Query MoreLikeThis(Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery moreLikeThisQuery) => new Query("more_like_this", moreLikeThisQuery);
	public static Query MultiMatch(Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery multiMatchQuery) => new Query("multi_match", multiMatchQuery);
	public static Query Nested(Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery nestedQuery) => new Query("nested", nestedQuery);
	public static Query ParentId(Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery parentIdQuery) => new Query("parent_id", parentIdQuery);
	public static Query Percolate(Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery percolateQuery) => new Query("percolate", percolateQuery);
	public static Query Pinned(Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery pinnedQuery) => new Query("pinned", pinnedQuery);
	public static Query Prefix(Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery prefixQuery) => new Query("prefix", prefixQuery);
	public static Query QueryString(Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery queryStringQuery) => new Query("query_string", queryStringQuery);
	public static Query Range(Elastic.Clients.Elasticsearch.QueryDsl.UntypedRangeQuery rangeQuery) => new Query("range", rangeQuery);
	public static Query Range(Elastic.Clients.Elasticsearch.QueryDsl.DateRangeQuery rangeQuery) => new Query("range", rangeQuery);
	public static Query Range(Elastic.Clients.Elasticsearch.QueryDsl.NumberRangeQuery rangeQuery) => new Query("range", rangeQuery);
	public static Query Range(Elastic.Clients.Elasticsearch.QueryDsl.TermRangeQuery rangeQuery) => new Query("range", rangeQuery);
	public static Query RankFeature(Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery rankFeatureQuery) => new Query("rank_feature", rankFeatureQuery);
	public static Query RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => new Query("raw_json", rawJsonQuery);
	public static Query Regexp(Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery regexpQuery) => new Query("regexp", regexpQuery);
	public static Query Rule(Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery ruleQuery) => new Query("rule", ruleQuery);
	public static Query Script(Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery scriptQuery) => new Query("script", scriptQuery);
	public static Query ScriptScore(Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery scriptScoreQuery) => new Query("script_score", scriptScoreQuery);
	public static Query Semantic(Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery semanticQuery) => new Query("semantic", semanticQuery);
	public static Query Shape(Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery shapeQuery) => new Query("shape", shapeQuery);
	public static Query SimpleQueryString(Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery simpleQueryStringQuery) => new Query("simple_query_string", simpleQueryStringQuery);
	public static Query SpanContaining(Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery spanContainingQuery) => new Query("span_containing", spanContainingQuery);
	public static Query SpanFieldMasking(Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery spanFieldMaskingQuery) => new Query("span_field_masking", spanFieldMaskingQuery);
	public static Query SpanFirst(Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery spanFirstQuery) => new Query("span_first", spanFirstQuery);
	public static Query SpanMulti(Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery spanMultiTermQuery) => new Query("span_multi", spanMultiTermQuery);
	public static Query SpanNear(Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery spanNearQuery) => new Query("span_near", spanNearQuery);
	public static Query SpanNot(Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery spanNotQuery) => new Query("span_not", spanNotQuery);
	public static Query SpanOr(Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery spanOrQuery) => new Query("span_or", spanOrQuery);
	public static Query SpanTerm(Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery spanTermQuery) => new Query("span_term", spanTermQuery);
	public static Query SpanWithin(Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery spanWithinQuery) => new Query("span_within", spanWithinQuery);
	public static Query SparseVector(Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery sparseVectorQuery) => new Query("sparse_vector", sparseVectorQuery);
	public static Query Term(Elastic.Clients.Elasticsearch.QueryDsl.TermQuery termQuery) => new Query("term", termQuery);
	public static Query Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery termsQuery) => new Query("terms", termsQuery);
	public static Query TermsSet(Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery termsSetQuery) => new Query("terms_set", termsSetQuery);
	public static Query TextExpansion(Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery textExpansionQuery) => new Query("text_expansion", textExpansionQuery);
	public static Query WeightedTokens(Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery weightedTokensQuery) => new Query("weighted_tokens", weightedTokensQuery);
	public static Query Wildcard(Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery wildcardQuery) => new Query("wildcard", wildcardQuery);
	public static Query Wrapper(Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery wrapperQuery) => new Query("wrapper", wrapperQuery);

	public bool TryGet<T>([NotNullWhen(true)] out T? result) where T : class
	{
		result = default;
		if (Variant is T variant)
		{
			result = variant;
			return true;
		}

		return false;
	}
}

internal sealed partial class QueryConverter : JsonConverter<Query>
{
	public override Query Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		if (reader.TokenType != JsonTokenType.StartObject)
		{
			throw new JsonException("Expected start token.");
		}

		object? variantValue = default;
		string? variantNameValue = default;
		while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
		{
			if (reader.TokenType != JsonTokenType.PropertyName)
			{
				throw new JsonException("Expected a property name token.");
			}

			if (reader.TokenType != JsonTokenType.PropertyName)
			{
				throw new JsonException("Expected a property name token representing the name of an Elasticsearch field.");
			}

			var propertyName = reader.GetString();
			reader.Read();
			if (propertyName == "bool")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "boosting")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "combined_fields")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "constant_score")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "dis_max")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "distance_feature")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.UntypedDistanceFeatureQuery>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "exists")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "function_score")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "fuzzy")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "geo_bounding_box")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "geo_distance")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "geo_shape")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "has_child")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "has_parent")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "ids")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "intervals")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "knn")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.KnnQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match_all")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match_bool_prefix")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match_none")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match_phrase")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "match_phrase_prefix")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "more_like_this")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "multi_match")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "nested")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "parent_id")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "percolate")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "pinned")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "prefix")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "query_string")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "range")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.UntypedRangeQuery>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "rank_feature")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "raw_json")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "regexp")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "rule")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "script")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "script_score")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "semantic")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "shape")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "simple_query_string")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_containing")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_field_masking")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_first")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_multi")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_near")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_not")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_or")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_term")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "span_within")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "sparse_vector")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "term")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "terms")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "terms_set")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "text_expansion")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "weighted_tokens")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "wildcard")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			if (propertyName == "wrapper")
			{
				variantValue = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery?>(ref reader, options);
				variantNameValue = propertyName;
				continue;
			}

			throw new JsonException($"Unknown property name '{propertyName}' received while deserializing the 'Query' from the response.");
		}

		var result = new Query(variantNameValue, variantValue);
		return result;
	}

	public override void Write(Utf8JsonWriter writer, Query value, JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		if (value.VariantName is not null && value.Variant is not null)
		{
			writer.WritePropertyName(value.VariantName);
			switch (value.VariantName)
			{
				case "bool":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery)value.Variant, options);
					break;
				case "boosting":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery)value.Variant, options);
					break;
				case "combined_fields":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery)value.Variant, options);
					break;
				case "constant_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery)value.Variant, options);
					break;
				case "dis_max":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery)value.Variant, options);
					break;
				case "distance_feature":
					JsonSerializer.Serialize(writer, value.Variant, value.Variant.GetType(), options);
					break;
				case "exists":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery)value.Variant, options);
					break;
				case "function_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery)value.Variant, options);
					break;
				case "fuzzy":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery)value.Variant, options);
					break;
				case "geo_bounding_box":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery)value.Variant, options);
					break;
				case "geo_distance":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery)value.Variant, options);
					break;
				case "geo_shape":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery)value.Variant, options);
					break;
				case "has_child":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery)value.Variant, options);
					break;
				case "has_parent":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery)value.Variant, options);
					break;
				case "ids":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery)value.Variant, options);
					break;
				case "intervals":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery)value.Variant, options);
					break;
				case "knn":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.KnnQuery>(writer, (Elastic.Clients.Elasticsearch.KnnQuery)value.Variant, options);
					break;
				case "match":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery)value.Variant, options);
					break;
				case "match_all":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery)value.Variant, options);
					break;
				case "match_bool_prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery)value.Variant, options);
					break;
				case "match_none":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery)value.Variant, options);
					break;
				case "match_phrase":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery)value.Variant, options);
					break;
				case "match_phrase_prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery)value.Variant, options);
					break;
				case "more_like_this":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery)value.Variant, options);
					break;
				case "multi_match":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery)value.Variant, options);
					break;
				case "nested":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery)value.Variant, options);
					break;
				case "parent_id":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery)value.Variant, options);
					break;
				case "percolate":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery)value.Variant, options);
					break;
				case "pinned":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery)value.Variant, options);
					break;
				case "prefix":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery)value.Variant, options);
					break;
				case "query_string":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery)value.Variant, options);
					break;
				case "range":
					JsonSerializer.Serialize(writer, value.Variant, value.Variant.GetType(), options);
					break;
				case "rank_feature":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery)value.Variant, options);
					break;
				case "raw_json":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery)value.Variant, options);
					break;
				case "regexp":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery)value.Variant, options);
					break;
				case "rule":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery)value.Variant, options);
					break;
				case "script":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery)value.Variant, options);
					break;
				case "script_score":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery)value.Variant, options);
					break;
				case "semantic":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery)value.Variant, options);
					break;
				case "shape":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery)value.Variant, options);
					break;
				case "simple_query_string":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery)value.Variant, options);
					break;
				case "span_containing":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery)value.Variant, options);
					break;
				case "span_field_masking":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery)value.Variant, options);
					break;
				case "span_first":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery)value.Variant, options);
					break;
				case "span_multi":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery)value.Variant, options);
					break;
				case "span_near":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery)value.Variant, options);
					break;
				case "span_not":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery)value.Variant, options);
					break;
				case "span_or":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery)value.Variant, options);
					break;
				case "span_term":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery)value.Variant, options);
					break;
				case "span_within":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery)value.Variant, options);
					break;
				case "sparse_vector":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery)value.Variant, options);
					break;
				case "term":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermQuery)value.Variant, options);
					break;
				case "terms":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery)value.Variant, options);
					break;
				case "terms_set":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery)value.Variant, options);
					break;
				case "text_expansion":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery)value.Variant, options);
					break;
				case "weighted_tokens":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery)value.Variant, options);
					break;
				case "wildcard":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery)value.Variant, options);
					break;
				case "wrapper":
					JsonSerializer.Serialize<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery>(writer, (Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery)value.Variant, options);
					break;
			}
		}

		writer.WriteEndObject();
	}
}

public sealed partial class QueryDescriptor<TDocument> : SerializableDescriptor<QueryDescriptor<TDocument>>
{
	internal QueryDescriptor(Action<QueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public QueryDescriptor() : base()
	{
	}

	private bool ContainsVariant { get; set; }
	private string ContainedVariantName { get; set; }
	private object Variant { get; set; }
	private Descriptor Descriptor { get; set; }

	private QueryDescriptor<TDocument> Set<T>(Action<T> descriptorAction, string variantName) where T : Descriptor
	{
		ContainedVariantName = variantName;
		ContainsVariant = true;
		var descriptor = (T)Activator.CreateInstance(typeof(T), true);
		descriptorAction?.Invoke(descriptor);
		Descriptor = descriptor;
		return Self;
	}

	private QueryDescriptor<TDocument> Set(object variant, string variantName)
	{
		Variant = variant;
		ContainedVariantName = variantName;
		ContainsVariant = true;
		return Self;
	}

	public QueryDescriptor<TDocument> Bool(Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery boolQuery) => Set(boolQuery, "bool");
	public QueryDescriptor<TDocument> Bool(Action<Elastic.Clients.Elasticsearch.QueryDsl.BoolQueryDescriptor<TDocument>> configure) => Set(configure, "bool");
	public QueryDescriptor<TDocument> Boosting(Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery boostingQuery) => Set(boostingQuery, "boosting");
	public QueryDescriptor<TDocument> Boosting(Action<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQueryDescriptor<TDocument>> configure) => Set(configure, "boosting");
	public QueryDescriptor<TDocument> CombinedFields(Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery combinedFieldsQuery) => Set(combinedFieldsQuery, "combined_fields");
	public QueryDescriptor<TDocument> CombinedFields(Action<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQueryDescriptor<TDocument>> configure) => Set(configure, "combined_fields");
	public QueryDescriptor<TDocument> ConstantScore(Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery constantScoreQuery) => Set(constantScoreQuery, "constant_score");
	public QueryDescriptor<TDocument> ConstantScore(Action<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQueryDescriptor<TDocument>> configure) => Set(configure, "constant_score");
	public QueryDescriptor<TDocument> DisMax(Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery disMaxQuery) => Set(disMaxQuery, "dis_max");
	public QueryDescriptor<TDocument> DisMax(Action<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQueryDescriptor<TDocument>> configure) => Set(configure, "dis_max");
	public QueryDescriptor<TDocument> DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.UntypedDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor<TDocument> DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor<TDocument> DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.DateDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor<TDocument> Exists(Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery existsQuery) => Set(existsQuery, "exists");
	public QueryDescriptor<TDocument> Exists(Action<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQueryDescriptor<TDocument>> configure) => Set(configure, "exists");
	public QueryDescriptor<TDocument> FunctionScore(Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery functionScoreQuery) => Set(functionScoreQuery, "function_score");
	public QueryDescriptor<TDocument> FunctionScore(Action<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQueryDescriptor<TDocument>> configure) => Set(configure, "function_score");
	public QueryDescriptor<TDocument> Fuzzy(Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery fuzzyQuery) => Set(fuzzyQuery, "fuzzy");
	public QueryDescriptor<TDocument> Fuzzy(Action<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQueryDescriptor<TDocument>> configure) => Set(configure, "fuzzy");
	public QueryDescriptor<TDocument> GeoBoundingBox(Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box");
	public QueryDescriptor<TDocument> GeoBoundingBox(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQueryDescriptor<TDocument>> configure) => Set(configure, "geo_bounding_box");
	public QueryDescriptor<TDocument> GeoDistance(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance");
	public QueryDescriptor<TDocument> GeoDistance(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQueryDescriptor<TDocument>> configure) => Set(configure, "geo_distance");
	public QueryDescriptor<TDocument> GeoShape(Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery geoShapeQuery) => Set(geoShapeQuery, "geo_shape");
	public QueryDescriptor<TDocument> GeoShape(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQueryDescriptor<TDocument>> configure) => Set(configure, "geo_shape");
	public QueryDescriptor<TDocument> HasChild(Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child");
	public QueryDescriptor<TDocument> HasChild(Action<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQueryDescriptor<TDocument>> configure) => Set(configure, "has_child");
	public QueryDescriptor<TDocument> HasParent(Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery hasParentQuery) => Set(hasParentQuery, "has_parent");
	public QueryDescriptor<TDocument> HasParent(Action<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQueryDescriptor<TDocument>> configure) => Set(configure, "has_parent");
	public QueryDescriptor<TDocument> Ids(Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery idsQuery) => Set(idsQuery, "ids");
	public QueryDescriptor<TDocument> Ids(Action<Elastic.Clients.Elasticsearch.QueryDsl.IdsQueryDescriptor> configure) => Set(configure, "ids");
	public QueryDescriptor<TDocument> Intervals(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery intervalsQuery) => Set(intervalsQuery, "intervals");
	public QueryDescriptor<TDocument> Intervals(Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQueryDescriptor<TDocument>> configure) => Set(configure, "intervals");
	public QueryDescriptor<TDocument> Knn(Elastic.Clients.Elasticsearch.KnnQuery knnQuery) => Set(knnQuery, "knn");
	public QueryDescriptor<TDocument> Knn(Action<Elastic.Clients.Elasticsearch.KnnQueryDescriptor<TDocument>> configure) => Set(configure, "knn");
	public QueryDescriptor<TDocument> Match(Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery matchQuery) => Set(matchQuery, "match");
	public QueryDescriptor<TDocument> Match(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchQueryDescriptor<TDocument>> configure) => Set(configure, "match");
	public QueryDescriptor<TDocument> MatchAll(Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery matchAllQuery) => Set(matchAllQuery, "match_all");
	public QueryDescriptor<TDocument> MatchAll(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQueryDescriptor> configure) => Set(configure, "match_all");
	public QueryDescriptor<TDocument> MatchBoolPrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery matchBoolPrefixQuery) => Set(matchBoolPrefixQuery, "match_bool_prefix");
	public QueryDescriptor<TDocument> MatchBoolPrefix(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_bool_prefix");
	public QueryDescriptor<TDocument> MatchNone(Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery matchNoneQuery) => Set(matchNoneQuery, "match_none");
	public QueryDescriptor<TDocument> MatchNone(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQueryDescriptor> configure) => Set(configure, "match_none");
	public QueryDescriptor<TDocument> MatchPhrase(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery matchPhraseQuery) => Set(matchPhraseQuery, "match_phrase");
	public QueryDescriptor<TDocument> MatchPhrase(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase");
	public QueryDescriptor<TDocument> MatchPhrasePrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery matchPhrasePrefixQuery) => Set(matchPhrasePrefixQuery, "match_phrase_prefix");
	public QueryDescriptor<TDocument> MatchPhrasePrefix(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQueryDescriptor<TDocument>> configure) => Set(configure, "match_phrase_prefix");
	public QueryDescriptor<TDocument> MoreLikeThis(Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery moreLikeThisQuery) => Set(moreLikeThisQuery, "more_like_this");
	public QueryDescriptor<TDocument> MoreLikeThis(Action<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQueryDescriptor<TDocument>> configure) => Set(configure, "more_like_this");
	public QueryDescriptor<TDocument> MultiMatch(Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery multiMatchQuery) => Set(multiMatchQuery, "multi_match");
	public QueryDescriptor<TDocument> MultiMatch(Action<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQueryDescriptor<TDocument>> configure) => Set(configure, "multi_match");
	public QueryDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery nestedQuery) => Set(nestedQuery, "nested");
	public QueryDescriptor<TDocument> Nested(Action<Elastic.Clients.Elasticsearch.QueryDsl.NestedQueryDescriptor<TDocument>> configure) => Set(configure, "nested");
	public QueryDescriptor<TDocument> ParentId(Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery parentIdQuery) => Set(parentIdQuery, "parent_id");
	public QueryDescriptor<TDocument> ParentId(Action<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQueryDescriptor> configure) => Set(configure, "parent_id");
	public QueryDescriptor<TDocument> Percolate(Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery percolateQuery) => Set(percolateQuery, "percolate");
	public QueryDescriptor<TDocument> Percolate(Action<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQueryDescriptor<TDocument>> configure) => Set(configure, "percolate");
	public QueryDescriptor<TDocument> Pinned(Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery pinnedQuery) => Set(pinnedQuery, "pinned");
	public QueryDescriptor<TDocument> Pinned(Action<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQueryDescriptor<TDocument>> configure) => Set(configure, "pinned");
	public QueryDescriptor<TDocument> Prefix(Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery prefixQuery) => Set(prefixQuery, "prefix");
	public QueryDescriptor<TDocument> Prefix(Action<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQueryDescriptor<TDocument>> configure) => Set(configure, "prefix");
	public QueryDescriptor<TDocument> QueryString(Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery queryStringQuery) => Set(queryStringQuery, "query_string");
	public QueryDescriptor<TDocument> QueryString(Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "query_string");
	public QueryDescriptor<TDocument> Range(Elastic.Clients.Elasticsearch.QueryDsl.UntypedRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor<TDocument> Range(Elastic.Clients.Elasticsearch.QueryDsl.DateRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor<TDocument> Range(Elastic.Clients.Elasticsearch.QueryDsl.NumberRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor<TDocument> Range(Elastic.Clients.Elasticsearch.QueryDsl.TermRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor<TDocument> RankFeature(Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery rankFeatureQuery) => Set(rankFeatureQuery, "rank_feature");
	public QueryDescriptor<TDocument> RankFeature(Action<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQueryDescriptor<TDocument>> configure) => Set(configure, "rank_feature");
	public QueryDescriptor<TDocument> RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => Set(rawJsonQuery, "raw_json");
	public QueryDescriptor<TDocument> Regexp(Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery regexpQuery) => Set(regexpQuery, "regexp");
	public QueryDescriptor<TDocument> Regexp(Action<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQueryDescriptor<TDocument>> configure) => Set(configure, "regexp");
	public QueryDescriptor<TDocument> Rule(Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery ruleQuery) => Set(ruleQuery, "rule");
	public QueryDescriptor<TDocument> Rule(Action<Elastic.Clients.Elasticsearch.QueryDsl.RuleQueryDescriptor<TDocument>> configure) => Set(configure, "rule");
	public QueryDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery scriptQuery) => Set(scriptQuery, "script");
	public QueryDescriptor<TDocument> Script(Action<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQueryDescriptor> configure) => Set(configure, "script");
	public QueryDescriptor<TDocument> ScriptScore(Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery scriptScoreQuery) => Set(scriptScoreQuery, "script_score");
	public QueryDescriptor<TDocument> ScriptScore(Action<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQueryDescriptor<TDocument>> configure) => Set(configure, "script_score");
	public QueryDescriptor<TDocument> Semantic(Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery semanticQuery) => Set(semanticQuery, "semantic");
	public QueryDescriptor<TDocument> Semantic(Action<Elastic.Clients.Elasticsearch.QueryDsl.SemanticQueryDescriptor> configure) => Set(configure, "semantic");
	public QueryDescriptor<TDocument> Shape(Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery shapeQuery) => Set(shapeQuery, "shape");
	public QueryDescriptor<TDocument> Shape(Action<Elastic.Clients.Elasticsearch.QueryDsl.ShapeQueryDescriptor<TDocument>> configure) => Set(configure, "shape");
	public QueryDescriptor<TDocument> SimpleQueryString(Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery simpleQueryStringQuery) => Set(simpleQueryStringQuery, "simple_query_string");
	public QueryDescriptor<TDocument> SimpleQueryString(Action<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQueryDescriptor<TDocument>> configure) => Set(configure, "simple_query_string");
	public QueryDescriptor<TDocument> SpanContaining(Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery spanContainingQuery) => Set(spanContainingQuery, "span_containing");
	public QueryDescriptor<TDocument> SpanContaining(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQueryDescriptor<TDocument>> configure) => Set(configure, "span_containing");
	public QueryDescriptor<TDocument> SpanFieldMasking(Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery spanFieldMaskingQuery) => Set(spanFieldMaskingQuery, "span_field_masking");
	public QueryDescriptor<TDocument> SpanFieldMasking(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQueryDescriptor<TDocument>> configure) => Set(configure, "span_field_masking");
	public QueryDescriptor<TDocument> SpanFirst(Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery spanFirstQuery) => Set(spanFirstQuery, "span_first");
	public QueryDescriptor<TDocument> SpanFirst(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQueryDescriptor<TDocument>> configure) => Set(configure, "span_first");
	public QueryDescriptor<TDocument> SpanMulti(Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery spanMultiTermQuery) => Set(spanMultiTermQuery, "span_multi");
	public QueryDescriptor<TDocument> SpanMulti(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_multi");
	public QueryDescriptor<TDocument> SpanNear(Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery spanNearQuery) => Set(spanNearQuery, "span_near");
	public QueryDescriptor<TDocument> SpanNear(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQueryDescriptor<TDocument>> configure) => Set(configure, "span_near");
	public QueryDescriptor<TDocument> SpanNot(Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery spanNotQuery) => Set(spanNotQuery, "span_not");
	public QueryDescriptor<TDocument> SpanNot(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQueryDescriptor<TDocument>> configure) => Set(configure, "span_not");
	public QueryDescriptor<TDocument> SpanOr(Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery spanOrQuery) => Set(spanOrQuery, "span_or");
	public QueryDescriptor<TDocument> SpanOr(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQueryDescriptor<TDocument>> configure) => Set(configure, "span_or");
	public QueryDescriptor<TDocument> SpanTerm(Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery spanTermQuery) => Set(spanTermQuery, "span_term");
	public QueryDescriptor<TDocument> SpanTerm(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQueryDescriptor<TDocument>> configure) => Set(configure, "span_term");
	public QueryDescriptor<TDocument> SpanWithin(Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery spanWithinQuery) => Set(spanWithinQuery, "span_within");
	public QueryDescriptor<TDocument> SpanWithin(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQueryDescriptor<TDocument>> configure) => Set(configure, "span_within");
	public QueryDescriptor<TDocument> SparseVector(Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery sparseVectorQuery) => Set(sparseVectorQuery, "sparse_vector");
	public QueryDescriptor<TDocument> SparseVector(Action<Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQueryDescriptor<TDocument>> configure) => Set(configure, "sparse_vector");
	public QueryDescriptor<TDocument> Term(Elastic.Clients.Elasticsearch.QueryDsl.TermQuery termQuery) => Set(termQuery, "term");
	public QueryDescriptor<TDocument> Term(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermQueryDescriptor<TDocument>> configure) => Set(configure, "term");
	public QueryDescriptor<TDocument> Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery termsQuery) => Set(termsQuery, "terms");
	public QueryDescriptor<TDocument> Terms(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryDescriptor<TDocument>> configure) => Set(configure, "terms");
	public QueryDescriptor<TDocument> TermsSet(Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery termsSetQuery) => Set(termsSetQuery, "terms_set");
	public QueryDescriptor<TDocument> TermsSet(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQueryDescriptor<TDocument>> configure) => Set(configure, "terms_set");
	public QueryDescriptor<TDocument> TextExpansion(Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery textExpansionQuery) => Set(textExpansionQuery, "text_expansion");
	public QueryDescriptor<TDocument> TextExpansion(Action<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQueryDescriptor<TDocument>> configure) => Set(configure, "text_expansion");
	public QueryDescriptor<TDocument> WeightedTokens(Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery weightedTokensQuery) => Set(weightedTokensQuery, "weighted_tokens");
	public QueryDescriptor<TDocument> WeightedTokens(Action<Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQueryDescriptor<TDocument>> configure) => Set(configure, "weighted_tokens");
	public QueryDescriptor<TDocument> Wildcard(Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery wildcardQuery) => Set(wildcardQuery, "wildcard");
	public QueryDescriptor<TDocument> Wildcard(Action<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQueryDescriptor<TDocument>> configure) => Set(configure, "wildcard");
	public QueryDescriptor<TDocument> Wrapper(Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery wrapperQuery) => Set(wrapperQuery, "wrapper");
	public QueryDescriptor<TDocument> Wrapper(Action<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQueryDescriptor> configure) => Set(configure, "wrapper");

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(ContainedVariantName))
		{
			writer.WritePropertyName(ContainedVariantName);
			if (Variant is not null)
			{
				JsonSerializer.Serialize(writer, Variant, Variant.GetType(), options);
				writer.WriteEndObject();
				return;
			}

			JsonSerializer.Serialize(writer, Descriptor, Descriptor.GetType(), options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class QueryDescriptor : SerializableDescriptor<QueryDescriptor>
{
	internal QueryDescriptor(Action<QueryDescriptor> configure) => configure.Invoke(this);

	public QueryDescriptor() : base()
	{
	}

	private bool ContainsVariant { get; set; }
	private string ContainedVariantName { get; set; }
	private object Variant { get; set; }
	private Descriptor Descriptor { get; set; }

	private QueryDescriptor Set<T>(Action<T> descriptorAction, string variantName) where T : Descriptor
	{
		ContainedVariantName = variantName;
		ContainsVariant = true;
		var descriptor = (T)Activator.CreateInstance(typeof(T), true);
		descriptorAction?.Invoke(descriptor);
		Descriptor = descriptor;
		return Self;
	}

	private QueryDescriptor Set(object variant, string variantName)
	{
		Variant = variant;
		ContainedVariantName = variantName;
		ContainsVariant = true;
		return Self;
	}

	public QueryDescriptor Bool(Elastic.Clients.Elasticsearch.QueryDsl.BoolQuery boolQuery) => Set(boolQuery, "bool");
	public QueryDescriptor Bool<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.BoolQueryDescriptor> configure) => Set(configure, "bool");
	public QueryDescriptor Boosting(Elastic.Clients.Elasticsearch.QueryDsl.BoostingQuery boostingQuery) => Set(boostingQuery, "boosting");
	public QueryDescriptor Boosting<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.BoostingQueryDescriptor> configure) => Set(configure, "boosting");
	public QueryDescriptor CombinedFields(Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQuery combinedFieldsQuery) => Set(combinedFieldsQuery, "combined_fields");
	public QueryDescriptor CombinedFields<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.CombinedFieldsQueryDescriptor> configure) => Set(configure, "combined_fields");
	public QueryDescriptor ConstantScore(Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQuery constantScoreQuery) => Set(constantScoreQuery, "constant_score");
	public QueryDescriptor ConstantScore<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.ConstantScoreQueryDescriptor> configure) => Set(configure, "constant_score");
	public QueryDescriptor DisMax(Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQuery disMaxQuery) => Set(disMaxQuery, "dis_max");
	public QueryDescriptor DisMax<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.DisMaxQueryDescriptor> configure) => Set(configure, "dis_max");
	public QueryDescriptor DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.UntypedDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor DistanceFeature(Elastic.Clients.Elasticsearch.QueryDsl.DateDistanceFeatureQuery distanceFeatureQuery) => Set(distanceFeatureQuery, "distance_feature");
	public QueryDescriptor Exists(Elastic.Clients.Elasticsearch.QueryDsl.ExistsQuery existsQuery) => Set(existsQuery, "exists");
	public QueryDescriptor Exists<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.ExistsQueryDescriptor> configure) => Set(configure, "exists");
	public QueryDescriptor FunctionScore(Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQuery functionScoreQuery) => Set(functionScoreQuery, "function_score");
	public QueryDescriptor FunctionScore<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.FunctionScoreQueryDescriptor> configure) => Set(configure, "function_score");
	public QueryDescriptor Fuzzy(Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQuery fuzzyQuery) => Set(fuzzyQuery, "fuzzy");
	public QueryDescriptor Fuzzy<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.FuzzyQueryDescriptor> configure) => Set(configure, "fuzzy");
	public QueryDescriptor GeoBoundingBox(Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQuery geoBoundingBoxQuery) => Set(geoBoundingBoxQuery, "geo_bounding_box");
	public QueryDescriptor GeoBoundingBox<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoBoundingBoxQueryDescriptor> configure) => Set(configure, "geo_bounding_box");
	public QueryDescriptor GeoDistance(Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQuery geoDistanceQuery) => Set(geoDistanceQuery, "geo_distance");
	public QueryDescriptor GeoDistance<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoDistanceQueryDescriptor> configure) => Set(configure, "geo_distance");
	public QueryDescriptor GeoShape(Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQuery geoShapeQuery) => Set(geoShapeQuery, "geo_shape");
	public QueryDescriptor GeoShape<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.GeoShapeQueryDescriptor> configure) => Set(configure, "geo_shape");
	public QueryDescriptor HasChild(Elastic.Clients.Elasticsearch.QueryDsl.HasChildQuery hasChildQuery) => Set(hasChildQuery, "has_child");
	public QueryDescriptor HasChild<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.HasChildQueryDescriptor> configure) => Set(configure, "has_child");
	public QueryDescriptor HasParent(Elastic.Clients.Elasticsearch.QueryDsl.HasParentQuery hasParentQuery) => Set(hasParentQuery, "has_parent");
	public QueryDescriptor HasParent<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.HasParentQueryDescriptor> configure) => Set(configure, "has_parent");
	public QueryDescriptor Ids(Elastic.Clients.Elasticsearch.QueryDsl.IdsQuery idsQuery) => Set(idsQuery, "ids");
	public QueryDescriptor Ids(Action<Elastic.Clients.Elasticsearch.QueryDsl.IdsQueryDescriptor> configure) => Set(configure, "ids");
	public QueryDescriptor Intervals(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery intervalsQuery) => Set(intervalsQuery, "intervals");
	public QueryDescriptor Intervals<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQueryDescriptor> configure) => Set(configure, "intervals");
	public QueryDescriptor Knn(Elastic.Clients.Elasticsearch.KnnQuery knnQuery) => Set(knnQuery, "knn");
	public QueryDescriptor Knn<TDocument>(Action<Elastic.Clients.Elasticsearch.KnnQueryDescriptor> configure) => Set(configure, "knn");
	public QueryDescriptor Match(Elastic.Clients.Elasticsearch.QueryDsl.MatchQuery matchQuery) => Set(matchQuery, "match");
	public QueryDescriptor Match<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchQueryDescriptor> configure) => Set(configure, "match");
	public QueryDescriptor MatchAll(Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQuery matchAllQuery) => Set(matchAllQuery, "match_all");
	public QueryDescriptor MatchAll(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchAllQueryDescriptor> configure) => Set(configure, "match_all");
	public QueryDescriptor MatchBoolPrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQuery matchBoolPrefixQuery) => Set(matchBoolPrefixQuery, "match_bool_prefix");
	public QueryDescriptor MatchBoolPrefix<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchBoolPrefixQueryDescriptor> configure) => Set(configure, "match_bool_prefix");
	public QueryDescriptor MatchNone(Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQuery matchNoneQuery) => Set(matchNoneQuery, "match_none");
	public QueryDescriptor MatchNone(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchNoneQueryDescriptor> configure) => Set(configure, "match_none");
	public QueryDescriptor MatchPhrase(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQuery matchPhraseQuery) => Set(matchPhraseQuery, "match_phrase");
	public QueryDescriptor MatchPhrase<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhraseQueryDescriptor> configure) => Set(configure, "match_phrase");
	public QueryDescriptor MatchPhrasePrefix(Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQuery matchPhrasePrefixQuery) => Set(matchPhrasePrefixQuery, "match_phrase_prefix");
	public QueryDescriptor MatchPhrasePrefix<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MatchPhrasePrefixQueryDescriptor> configure) => Set(configure, "match_phrase_prefix");
	public QueryDescriptor MoreLikeThis(Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQuery moreLikeThisQuery) => Set(moreLikeThisQuery, "more_like_this");
	public QueryDescriptor MoreLikeThis<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MoreLikeThisQueryDescriptor> configure) => Set(configure, "more_like_this");
	public QueryDescriptor MultiMatch(Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQuery multiMatchQuery) => Set(multiMatchQuery, "multi_match");
	public QueryDescriptor MultiMatch<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.MultiMatchQueryDescriptor> configure) => Set(configure, "multi_match");
	public QueryDescriptor Nested(Elastic.Clients.Elasticsearch.QueryDsl.NestedQuery nestedQuery) => Set(nestedQuery, "nested");
	public QueryDescriptor Nested<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.NestedQueryDescriptor> configure) => Set(configure, "nested");
	public QueryDescriptor ParentId(Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQuery parentIdQuery) => Set(parentIdQuery, "parent_id");
	public QueryDescriptor ParentId(Action<Elastic.Clients.Elasticsearch.QueryDsl.ParentIdQueryDescriptor> configure) => Set(configure, "parent_id");
	public QueryDescriptor Percolate(Elastic.Clients.Elasticsearch.QueryDsl.PercolateQuery percolateQuery) => Set(percolateQuery, "percolate");
	public QueryDescriptor Percolate<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.PercolateQueryDescriptor> configure) => Set(configure, "percolate");
	public QueryDescriptor Pinned(Elastic.Clients.Elasticsearch.QueryDsl.PinnedQuery pinnedQuery) => Set(pinnedQuery, "pinned");
	public QueryDescriptor Pinned<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.PinnedQueryDescriptor> configure) => Set(configure, "pinned");
	public QueryDescriptor Prefix(Elastic.Clients.Elasticsearch.QueryDsl.PrefixQuery prefixQuery) => Set(prefixQuery, "prefix");
	public QueryDescriptor Prefix<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.PrefixQueryDescriptor> configure) => Set(configure, "prefix");
	public QueryDescriptor QueryString(Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQuery queryStringQuery) => Set(queryStringQuery, "query_string");
	public QueryDescriptor QueryString<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryStringQueryDescriptor> configure) => Set(configure, "query_string");
	public QueryDescriptor Range(Elastic.Clients.Elasticsearch.QueryDsl.UntypedRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor Range(Elastic.Clients.Elasticsearch.QueryDsl.DateRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor Range(Elastic.Clients.Elasticsearch.QueryDsl.NumberRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor Range(Elastic.Clients.Elasticsearch.QueryDsl.TermRangeQuery rangeQuery) => Set(rangeQuery, "range");
	public QueryDescriptor RankFeature(Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQuery rankFeatureQuery) => Set(rankFeatureQuery, "rank_feature");
	public QueryDescriptor RankFeature<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.RankFeatureQueryDescriptor> configure) => Set(configure, "rank_feature");
	public QueryDescriptor RawJson(Elastic.Clients.Elasticsearch.QueryDsl.RawJsonQuery rawJsonQuery) => Set(rawJsonQuery, "raw_json");
	public QueryDescriptor Regexp(Elastic.Clients.Elasticsearch.QueryDsl.RegexpQuery regexpQuery) => Set(regexpQuery, "regexp");
	public QueryDescriptor Regexp<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.RegexpQueryDescriptor> configure) => Set(configure, "regexp");
	public QueryDescriptor Rule(Elastic.Clients.Elasticsearch.QueryDsl.RuleQuery ruleQuery) => Set(ruleQuery, "rule");
	public QueryDescriptor Rule<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.RuleQueryDescriptor> configure) => Set(configure, "rule");
	public QueryDescriptor Script(Elastic.Clients.Elasticsearch.QueryDsl.ScriptQuery scriptQuery) => Set(scriptQuery, "script");
	public QueryDescriptor Script(Action<Elastic.Clients.Elasticsearch.QueryDsl.ScriptQueryDescriptor> configure) => Set(configure, "script");
	public QueryDescriptor ScriptScore(Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQuery scriptScoreQuery) => Set(scriptScoreQuery, "script_score");
	public QueryDescriptor ScriptScore<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.ScriptScoreQueryDescriptor> configure) => Set(configure, "script_score");
	public QueryDescriptor Semantic(Elastic.Clients.Elasticsearch.QueryDsl.SemanticQuery semanticQuery) => Set(semanticQuery, "semantic");
	public QueryDescriptor Semantic(Action<Elastic.Clients.Elasticsearch.QueryDsl.SemanticQueryDescriptor> configure) => Set(configure, "semantic");
	public QueryDescriptor Shape(Elastic.Clients.Elasticsearch.QueryDsl.ShapeQuery shapeQuery) => Set(shapeQuery, "shape");
	public QueryDescriptor Shape<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.ShapeQueryDescriptor> configure) => Set(configure, "shape");
	public QueryDescriptor SimpleQueryString(Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQuery simpleQueryStringQuery) => Set(simpleQueryStringQuery, "simple_query_string");
	public QueryDescriptor SimpleQueryString<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SimpleQueryStringQueryDescriptor> configure) => Set(configure, "simple_query_string");
	public QueryDescriptor SpanContaining(Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQuery spanContainingQuery) => Set(spanContainingQuery, "span_containing");
	public QueryDescriptor SpanContaining<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanContainingQueryDescriptor> configure) => Set(configure, "span_containing");
	public QueryDescriptor SpanFieldMasking(Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQuery spanFieldMaskingQuery) => Set(spanFieldMaskingQuery, "span_field_masking");
	public QueryDescriptor SpanFieldMasking<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanFieldMaskingQueryDescriptor> configure) => Set(configure, "span_field_masking");
	public QueryDescriptor SpanFirst(Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQuery spanFirstQuery) => Set(spanFirstQuery, "span_first");
	public QueryDescriptor SpanFirst<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanFirstQueryDescriptor> configure) => Set(configure, "span_first");
	public QueryDescriptor SpanMulti(Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQuery spanMultiTermQuery) => Set(spanMultiTermQuery, "span_multi");
	public QueryDescriptor SpanMulti<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanMultiTermQueryDescriptor> configure) => Set(configure, "span_multi");
	public QueryDescriptor SpanNear(Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQuery spanNearQuery) => Set(spanNearQuery, "span_near");
	public QueryDescriptor SpanNear<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanNearQueryDescriptor> configure) => Set(configure, "span_near");
	public QueryDescriptor SpanNot(Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQuery spanNotQuery) => Set(spanNotQuery, "span_not");
	public QueryDescriptor SpanNot<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanNotQueryDescriptor> configure) => Set(configure, "span_not");
	public QueryDescriptor SpanOr(Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQuery spanOrQuery) => Set(spanOrQuery, "span_or");
	public QueryDescriptor SpanOr<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanOrQueryDescriptor> configure) => Set(configure, "span_or");
	public QueryDescriptor SpanTerm(Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQuery spanTermQuery) => Set(spanTermQuery, "span_term");
	public QueryDescriptor SpanTerm<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanTermQueryDescriptor> configure) => Set(configure, "span_term");
	public QueryDescriptor SpanWithin(Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQuery spanWithinQuery) => Set(spanWithinQuery, "span_within");
	public QueryDescriptor SpanWithin<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanWithinQueryDescriptor> configure) => Set(configure, "span_within");
	public QueryDescriptor SparseVector(Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQuery sparseVectorQuery) => Set(sparseVectorQuery, "sparse_vector");
	public QueryDescriptor SparseVector<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.SparseVectorQueryDescriptor> configure) => Set(configure, "sparse_vector");
	public QueryDescriptor Term(Elastic.Clients.Elasticsearch.QueryDsl.TermQuery termQuery) => Set(termQuery, "term");
	public QueryDescriptor Term<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermQueryDescriptor> configure) => Set(configure, "term");
	public QueryDescriptor Terms(Elastic.Clients.Elasticsearch.QueryDsl.TermsQuery termsQuery) => Set(termsQuery, "terms");
	public QueryDescriptor Terms<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryDescriptor> configure) => Set(configure, "terms");
	public QueryDescriptor TermsSet(Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQuery termsSetQuery) => Set(termsSetQuery, "terms_set");
	public QueryDescriptor TermsSet<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.TermsSetQueryDescriptor> configure) => Set(configure, "terms_set");
	public QueryDescriptor TextExpansion(Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQuery textExpansionQuery) => Set(textExpansionQuery, "text_expansion");
	public QueryDescriptor TextExpansion<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.TextExpansionQueryDescriptor> configure) => Set(configure, "text_expansion");
	public QueryDescriptor WeightedTokens(Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQuery weightedTokensQuery) => Set(weightedTokensQuery, "weighted_tokens");
	public QueryDescriptor WeightedTokens<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.WeightedTokensQueryDescriptor> configure) => Set(configure, "weighted_tokens");
	public QueryDescriptor Wildcard(Elastic.Clients.Elasticsearch.QueryDsl.WildcardQuery wildcardQuery) => Set(wildcardQuery, "wildcard");
	public QueryDescriptor Wildcard<TDocument>(Action<Elastic.Clients.Elasticsearch.QueryDsl.WildcardQueryDescriptor> configure) => Set(configure, "wildcard");
	public QueryDescriptor Wrapper(Elastic.Clients.Elasticsearch.QueryDsl.WrapperQuery wrapperQuery) => Set(wrapperQuery, "wrapper");
	public QueryDescriptor Wrapper(Action<Elastic.Clients.Elasticsearch.QueryDsl.WrapperQueryDescriptor> configure) => Set(configure, "wrapper");

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(ContainedVariantName))
		{
			writer.WritePropertyName(ContainedVariantName);
			if (Variant is not null)
			{
				JsonSerializer.Serialize(writer, Variant, Variant.GetType(), options);
				writer.WriteEndObject();
				return;
			}

			JsonSerializer.Serialize(writer, Descriptor, Descriptor.GetType(), options);
		}

		writer.WriteEndObject();
	}
}